#!/bin/bash

# 下载什么
NAME=$1
# 哪个版本
VERSION=$2

P3=$3
P4=$4

function on_fail() {
	NAME=""
	VERSION=""
	printf "\n> \033[31m下载失败！\033[0m\n\n"
}

function start() {
	if [ "$VERSION" == "" ];then
		VERSION='latest'
	fi
	printf '\n> 正在请求下载%s@%s...\n' ${NAME} ${VERSION}
	curl -s https://gitee.com/xiaozhu2022/auto-install/${NAME} | sh -s ${VERSION} ${P3} ${P4} || on_fail
}

function check_param() {
		case $NAME in
			'')
				clear
				printf "可安装的脚本:\n"
				printf "  \033[1m\033[32m%s\033[0m %s \t (docs: %s) \n" 'get_nodejs.sh' '' 'https://'
				printf "  \033[1m\033[32m%s\033[0m %s \t (docs: %s) \n" 'get_python.sh' '' 'https://'
				printf "\n"
				printf "默认安装最新版本，可以在脚本后面加上版本号安装指定版本，用空格隔开。\n"
				printf "\n\n"
			;;
			*) start ;;
		esac
}


check_param
